import {createRouter, createWebHashHistory} from "vue-router";
import Home from "../views/Home.vue";

const routes = [
    {
        path: "/login",
        name: "Login",
        meta: {
            title: '登录'
        },
        component: () => import ("../views/Login.vue")
    },
    {
        path: '/',
        redirect: '/barData'
    },
    {
        path: "/",
        name: "Home",
        component: Home,
        children: [
            {
                path: "/notice",
                name: "notice",
                meta: {
                    title: '公告信息'
                },
                component: () => import ("../views/temp/Notice.vue")
            },
            {
                path: "/new",
                name: "new",
                meta: {
                    title: '数据统计'
                },
                component: () => import ("../views/temp/New.vue")
            },
            {
                path: "/noticeForm",
                name: "noticeForm",
                meta: {
                    title: '新增公告'
                },
                component: () => import ("../views/temp/NoticeForm.vue")
            },
            {
                path: "/user",
                name: "user",
                meta: {
                    title: '用户信息'
                },
                component: () => import ("../views/temp/User.vue")
            },
            {
                path: "/userInfoAudit",
                name: "userInfoAudit",
                meta: {
                    title: '实名认证审核'
                },
                component: () => import ("../views/temp/UserInfoAudit.vue")
            },
            {
                path: "/collectorAudit",
                name: "collectorAudit",
                meta: {
                    title: '回收员资格审核'
                },
                component: () => import ("../views/temp/CollectorAudit.vue")
            },
            {
                path: "/category",
                name: "category",
                meta: {
                    title: '类别信息'
                },
                component: () => import ("../views/temp/Category.vue")
            },
            {
                path: "/item",
                name: "item",
                meta: {
                    title: '类别信息'
                },
                component: () => import ("../views/temp/Item.vue")
            },
            {
                path: "/order",
                name: "order",
                meta: {
                    title: '订单信息'
                },
                component: () => import ("../views/temp/Order.vue")
            },
            {
                path: "/barData",
                name: "barData",
                meta: {
                    title: '柱状图'
                },
                component: () => import ("../views/temp/BarData.vue")
            },
            {
                path: "/pieData",
                name: "pieData",
                meta: {
                    title: '饼状图'
                },
                component: () => import ("../views/temp/PieData.vue")
            },
            {
                path: "/adminUpdateForm",
                name: "adminUpdateForm",
                meta: {
                    title: '修改密码'
                },
                component: () => import ("../views/temp/adminUpdateForm.vue")
            },
            {
                path: "/admin",
                name: "admin",
                meta: {
                    title: '账号信息'
                },
                component: () => import ("../views/temp/admin.vue")
            },
            {
                path: "/dashboard",
                name: "dashboard",
                meta: {
                    title: '系统首页'
                },
                component: () => import ( /* webpackChunkName: "dashboard" */ "../views/Dashboard.vue")
            },{
                path: '/404',
                name: '404',
                meta: {
                    title: '找不到页面'
                },
                component: () => import (/* webpackChunkName: "404" */ '../views/404.vue')
            }, {
                path: '/403',
                name: '403',
                meta: {
                    title: '没有权限'
                },
                component: () => import (/* webpackChunkName: "403" */ '../views/403.vue')
            }
        ]
    }
];

const router = createRouter({
    history: createWebHashHistory(),
    routes
});

router.beforeEach((to, from, next) => {
    document.title = "environment-system";
    const username = localStorage.getItem('username');
    if (!username && to.path !== '/login') {
        next('/login');
    } else {
        next();
    }
});

export default router;